<?php
namespace App\Traits;

trait ModelLabelTrait{
    public static function getLabels($prefix){
        $ref= new \ReflectionClass(static::class);
        $constants = $ref->getConstants();
        $prefix = strtoupper($prefix);
        return $constants[$prefix.'_LABELS'];
    }

    public static function getLabel($prefix,$key){
        $labels = static::getLabels($prefix);
        return isset($labels[$key])?$labels[$key]:'';
    }

    public static function getHtml($prefix){
        $ref= new \ReflectionClass(static::class);
        $constants = $ref->getConstants();
        $prefix = strtoupper($prefix);
        return $constants[$prefix.'_HTML'];
    }

    public static function getMessages($prefix){
        $ref= new \ReflectionClass(static::class);
        $constants = $ref->getConstants();
        $prefix = strtoupper($prefix);
        return $constants[$prefix.'_MESSAGE'];
    }

    public static function getMessage($field,$key){
        $messages = static::getMessages($field);
        return $messages[$key];
    }

    public static function fieldHtml($field,$value,$class='btn btn-sm'){
        $orderstatus = static::getLabels($field);
        $text=$orderstatus[$value];
        $html = static::getHtml($field);
        $color = $html[$value];
        return "<span class='".$class.' '.$color."'>".$text."</span>";
    }
}